/*
 * HasPtr.cpp
 *
 *  Created on: 2020年11月29日
 *      Author: san
 */

#include <HasPtrLikePoint.h>


HasPtrLikePoint::HasPtrLikePoint(const HasPtrLikePoint &h): ps(new std::string(*h.ps)), i(h.i), use(h.use)
{
	// 拷贝构造函数
	++*use;
}

HasPtrLikePoint &HasPtrLikePoint::operator=(const HasPtrLikePoint &h)
{
	// 重载赋值运算符
	++*h.use;

	// 如果本对象的引用计数为0，则delete
	if (--*use == 0)
	{
		delete ps;
		delete use;
	}

	ps = h.ps;
	i = h.i;
	use = h.use;
	return *this;
}

HasPtrLikePoint::~HasPtrLikePoint() {
	// TODO Auto-generated destructor stub
	if (--*use == 0)
	{
		delete ps;
		delete use;
	}
}

